package com.wanmait.movie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.movie.entity.Actor;
import com.wanmait.movie.mapper.ActorMapper;
import com.wanmait.movie.service.ActorService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class ActorServiceImpl extends ServiceImpl<ActorMapper, Actor> implements ActorService {
    @Resource
    private ActorMapper actorMapper;


    @Override
    public PageInfo<Actor> getActorList(String keyword,int pageNum,int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        LambdaQueryWrapper<Actor> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByDesc(Actor::getSort);
        if (keyword!=null){
            queryWrapper.like(Actor::getName,keyword).or().like(Actor::getRole,keyword);
        }
        List<Actor> actors = actorMapper.selectList(queryWrapper);
        return new PageInfo<>(actors);
    }
    @Override
    public String getDirector(int id){
       Actor actor= actorMapper.selectById(id);
       String name=actor.getName();
        return name;
    }
    @Override
    public List<Actor> getDirectorList() {
        LambdaQueryWrapper<Actor> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Actor::getRole,"导演");
        return actorMapper.selectList(queryWrapper);
    }

    @Override
    public List<Actor> getStar() {
        LambdaQueryWrapper<Actor> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Actor::getRole,"演员");
        return actorMapper.selectList(queryWrapper);
    }
}
